package com.eff.android;

import com.eff.android.lib.asynctask.EAsyncTask;
import com.eff.android.lib.asynctask.EBackgroundAsyncTask;
import com.eff.android.lib.asynctask.EIAsyncTaskCallback;
import com.eff.android.lib.asynctask.EIBackgroundAsyncTaskCallback;
import com.eff.android.lib.connection.EDataConnection;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

public class ESplashScreenActivity extends EBaseActivity{

	public static String TAG = ESplashScreenActivity.class.getSimpleName();

    @Override
    public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
    	setContentView(R.layout.e_activity_splash);
    	
    	getActionBar().hide();
    	
    	loadGetDataThread();
    	loadSplashThread();
    }

    private void loadSplashThread() {
    	new EAsyncTask(new EIAsyncTaskCallback() {
    	    @Override
    	    public void processBackground() {
    		try {
    		    Thread.sleep(2000l);
    		} catch (InterruptedException e) {
    		    Log.d(TAG, e.getMessage());
    		}
    	    }

    	    @Override
    	    public void processCompleted(String result) {
    	    	openMainActivity();
    	    }

    	}).exec();
    }
    
    private void loadGetDataThread(){
    	new EBackgroundAsyncTask(new EIBackgroundAsyncTaskCallback() {
			
			@Override
			public void processBackground() {
				EDataConnection dataConn = new EDataConnection(getApplicationContext());
				dataConn.doInBackground();
			}
		}).exec();
    }

    private void openMainActivity() {
		Intent intent = new Intent();
		intent.setClass(ESplashScreenActivity.this, EMainActivity.class);
		intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		startActivity(intent);
		
		finish();
    }

}
